<template>
  <div class="_wz_cent_main _wz_IncuExamReco">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="从业人员">
          <i-input type="text" v-model="formDataSearch.driverName" placeholder="从业人员" clearable />
        </FormItem>
        <FormItem label="身份证号">
          <i-input type="text" v-model="formDataSearch.driverIdentifyNum" placeholder="身份证号" clearable />
        </FormItem>
        <FormItem label="联系电话" v-if="searchType">
          <i-input type="text" v-model="formDataSearch.driverPhone" placeholder="联系电话" clearable />
        </FormItem>
        <FormItem label="从业类型" v-if="searchType">
          <i-select v-model="formDataSearch.driverType" filterable placeholder="从业类型" clearable>
            <Option v-for="item in personType" :value="item.code" :key="item.code">{{item.value}}</Option>
          </i-select>
        </FormItem>
        <FormItem label="驾乘车辆" v-if="searchType">
          <i-input type="text" v-model="formDataSearch.driverVehiclePlate" placeholder="驾乘车辆" clearable />
        </FormItem>
        <FormItem label="考试周期" prop="wzYearMonth" v-if="searchType">
          <DatePicker type="month" v-model="formDataSearch.wzYearMonth" placeholder="请选择年月"></DatePicker>
        </FormItem>
        <FormItem label="考试情况" v-if="searchType">
          <i-select v-model="formDataSearch.finishState" filterable placeholder="考试情况" clearable>
            <Option value="0">未开始</Option>
            <Option value="1">考试及格</Option>
            <Option value="2">不及格</Option>
          </i-select>
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>

    <Drawer :title="headline" :closable="true" v-model="modal" width="800" :draggable="true">
      <grade v-if="modal" :selectData="examDetails"></grade>
    </Drawer>
  </div>
</template>
<script>
  import grade from './grade.vue'
  import PrintLearning from './PrintLearning.vue'
  import wzTbale from "../../../components/table/table";


  export default {
    components: {
      grade,//试题成绩
      PrintLearning,//打印情况
      wzTbale,//列表
    },
    data() {
      return {
        searchType:false,//搜索条件
        subDeptList: [],//运输企业
        personType: [],//从业类型
        headline: "",//弹框标题
        modal: false,//弹出层状态
        materialData: null,//选择素材的所有数据
        materialType: 0,//6 试题   5 html   1 视频   7 打印情况
        tableData: {
          url: this.apiUrl.webApi + "/educate/examPlan/examStudentPlanPageList",//请求地址
          method: 'post',//请求方式
          where: {},//搜索条件
          height: 'auto',//表格高度 auto
          page: true,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 70, align: 'center', title: '序号'},
            {title: '从业人员', key: 'driverName', minWidth: 90},
            {title: '从业类型', key: 'driverTypeName', minWidth: 100},
            {title: '驾乘车辆', key: 'driverVehicleNo', minWidth: 100},
            {
              title: '考试周期', key: '', minWidth: 120, render: (h, params) => {
                return h('span', params.row.examStudentCreateYear + "年" + params.row.examStudentCreateMonth + "月");
              }
            },
            {title: '考试名称', key: 'examPlanName', minWidth: 200},
            {title: '试卷类型', key: 'materialExamTransportTypeName', minWidth: 100},
            {title: '试卷名称', key: 'materialExamName', minWidth: 160},
            {
              title: '考试情况', key: '', minWidth: 140, render: (h, params) => {
                return h('Tag', {
                  props: {
                    type: 'dot',
                    color: (params.row.examStudentPass == 0) ? "" : (params.row.examStudentPass == 1) ? "success" : "warning"
                  }
                }, (params.row.examStudentPass == 0) ? "未开始" : (params.row.examStudentPass == 1) ? "考试及格" : "不及格");
              }
            },
            {
              title: '考试次数', key: 'examStudentScore', minWidth: 100, render: (h, params) => {
                return h('div', params.row.examStudentCount + "次");
              }
            },
            {
              title: '考试得分', key: 'examStudentScore', minWidth: 100, render: (h, params) => {
                return h('div', params.row.examStudentScore + "分");
              }
            },
            {
              title: '及格分数', key: 'examStudentPassScore', minWidth: 100, render: (h, params) => {
                return h('div', (!!params.row.examStudentPassScore ? params.row.examStudentPassScore : 0) + "分");
              }
            },
            {
              title: '考试总分', key: 'examStudentTotalScore', minWidth: 100, render: (h, params) => {
                return h('div', (!!params.row.examStudentTotalScore ? params.row.examStudentTotalScore : 0) + "分");
              }
            },
            {
              title: '考试用时', key: 'examStudentUseDuration', minWidth: 100, render: (h, params) => {
                return h('div', parseInt(params.row.examStudentUseDuration / 60) +' 分钟 '+ params.row.examStudentUseDuration % 60 +' 秒');
              }
            },
            {title: '运输企业', key: 'deptName', minWidth: 260},
            {
              title: '操作', fixed: 'right', width: 100, render: (h, params) => {
                var test = h('span', "");
                if (!!params.row.examStudentScore) {
                  test = h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.Achievement(params.row)
                      }
                    }
                  }, "查看")
                }
                return test;
              }
            },
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
            count: ['count'],//数据总量
          },
        },
        formDataSearch: {},
      }
    },
    beforeCreate() {//beforeCreate创建前状态

    },
    created() {//created创建完毕状态

    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
      let that = this;



      //运输企业
      that.axios.post(that.apiUrl.coreDeptCoreDeptList,{}).then(res => {
        if (!!res) {
          that.subDeptList = res.data.data;
        }
      }).catch(err => {
        console.log("失败", err)
      })
      //从业类型
      that.axios.post(that.apiUrl.systemDictSystemDictList,{type:'person_type'}).then(res => {
        if (!!res) {
          that.personType = res.data.data;
        }
      }).catch(err => {
        console.log('失败', err);
      })

    },
    methods: {//执行的方法
      //个人成绩
      Achievement(data) {
        let that = this;
        that.headline = data.driverName + "考试成绩";
        that.axios.post(that.apiUrl.webApi + "/educate/examPlan/examStudentPlanInfo", {uuid: data.uuid}).then(res => {
          if (!!res) {
            //考试
            var imgList = [];
            !!res.data.data.examStudentFirstImg ? imgList.push(res.data.data.examStudentFirstImg) : "";
            !!res.data.data.examStudentSecondImg ? imgList.push(res.data.data.examStudentSecondImg) : "";
            !!res.data.data.examStudentThirdImg ? imgList.push(res.data.data.examStudentThirdImg) : "";
            res.data.data.imgList = imgList;
            that.examDetails = res.data.data;
            that.modal = true;
          }
        }).catch(err => {
          console.log('失败', err);
        })
      },
      //搜索
      searchSubmit() {
        //
        // this.formDataSearch.createYear = !!this.formDataSearch.wzYearMonth?this.public.timeFormatting(this.formDataSearch.wzYearMonth, "yyyy"):'';
        // this.formDataSearch.createMonth = !!this.formDataSearch.wzYearMonth?this.public.timeFormatting(this.formDataSearch.wzYearMonth, "MM"):'';
        this.formDataSearch.createDate = !!this.formDataSearch.wzYearMonth?this.public.timeFormatting(this.formDataSearch.wzYearMonth, "yyyy-MM"):'';

        this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
        this.$refs.wzTbale.tableLoadData(true);
      },
    },
    watch: {//监听

    },
    props: {//接收来自父组件的数据

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>
<style lang="less">
  ._wz_IncuExamReco {
    height: 100%;
    display: flex;
    flex-direction: column;

  }

</style>
